﻿@using NGroup.VTL.Models;
@using NGroup.VTL.Core.Const;
@{
    ViewBag.Title = "Quản trị - Danh sách người dùng";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
    List<UserModel> userList = ViewBag.UserList as List<UserModel>;
}
@if (userList != null)
{
    using (Html.BeginForm("them_nguoi_dung", "vuarao", FormMethod.Post, new { id = "MainUser", style = "display: none" }))
    {
    <div>
        <p>
            <label>
                Họ và tên</label><input class="text-input large-input" id="userAliasNew" name="userAlias"
                    type="text" />
        </p>
        <p>
            <label>
                Username</label><input class="text-input large-input" type="text" id="usernameNew" name="username" />
        </p>
        <p>
            <label>
                Password</label><input class="text-input large-input" type="password" id="passwordNew"
                    name="password" />
        </p>
        
        <p>
            <input class="button align-right" onmousedown="clickFix(this)" type="submit" value="Thêm" id="btnAddNewUser" />
            <br class="clear" />
        </p>
    </div>
    } 
     using (Html.BeginForm("sua_nguoi_dung", "vuarao", FormMethod.Post, new { id = "MainEditUser", style = "display: none" }))
    {
    <div>
        <p>
            <label>
                Username</label><input class="text-input large-input" readonly="readonly" type="text" id="usernameEdit" name="editUsername" />
        </p>
        <p>
            <label>
                Password</label><input class="text-input large-input" type="password" id="passwordEdit"  name="editPassword" />
        </p>       
        <p>
            <input class="button align-right" onmousedown="clickFix(this)" type="submit" value="Sửa" id="btnEditUser" />
            <br class="clear" />
        </p>
    </div>
    }   
    <div class="clear">
    </div>
    <!-- End .clear -->
    <div class="content-box">
        <!-- Start Content Box -->
        <div class="content-box-header">
            <h3>
                Danh Sách Người Dùng</h3>
            <div class="filterGroup">
                <a href="#MainUser" rel="modal" title="Thêm">
                    <img src="@Url.Content("~/Content/adminpages/images/icons/add-sign-32.png")" alt="Thêm" /></a>
               
            </div>
            <div class="clear">
            </div>
           
        </div>
        <div class="clear">
        </div>
        <!-- End .content-box-header -->
        <div class="content-box-content">
            <div class="tab-content default-tab" id="tab1">
                <!-- This is the target div. id must match the href of this div's tab -->
                
                <table>
                    <thead>
                        <tr>
                           
                            <th>
                                Tài khoản
                            </th>
                            <th>
                                Người tạo
                            </th>
                            <th>
                                Ngày tạo
                            </th>
                            <th>
                                Phân quyền
                            </th>
                           
                            <th>
                                Công cụ
                            </th>
                        </tr>
                    </thead>
                    <tfoot>
                        <tr>
                            <td colspan="5">
                               
                                <!-- End .pagination -->
                                <div class="clear">
                                </div>
                            </td>
                        </tr>
                    </tfoot>
                    <tbody>
                        @foreach (UserModel user in userList)
                        {
                            <tr>
                                @*<td>
                                    <input type="checkbox" />
                                </td>*@
                                <td>
                                    <a href="#" title="Username">@user.Username</a>
                                </td>
                                <td>
                                    @if (string.IsNullOrWhiteSpace(user.CreatedBy))
                                    {
                                        @Html.Raw("-");
                                    }
                                    else
                                    {
                                        @user.CreatedBy;
                                    }
                                </td>
                                <td>
                                    @if (string.IsNullOrWhiteSpace(user.CreatedAt.ToString()))
                                    {
                                        <span>-</span>
                                    }
                                    else
                                    {
                                        <span>@user.CreatedAt.ToString()</span>
                                    }
                                </td>
                                <td>
                                    @if (user.RoleID == Convert.ToInt32(VTLPermission.Admin))
                                    {
                                        <span>Admin</span>
                                    }
                                    else if (user.RoleID == Convert.ToInt32(VTLPermission.SystemAdmin))
                                    {
                                        <span>System Admin</span>
                                    }
                                    else
                                    {
                                        <span>N/A</span>
                                    }
                                </td>
                                @*<td>
                                    <img class="pCenter" src="@Url.Content("~/Content/adminpages/images/icons/eye-open-20.png")" title="Hiện" alt="Hiện" />
                                </td>*@
                                <td>
                                    <!-- Icons -->
                                    <a href="#MainEditUser" onclick="EditUser('@user.Username')" class="editUser" rel="modal" title="Edit">
                                        <img src="@Url.Content("~/Content/adminpages/images/icons/pencil.png")" alt="Edit" /></a>
                                    <a href="/vuarao/delete-user/@user.UserID" class="btnDelete" title="Delete">
                                        <img src="@Url.Content("~/Content/adminpages/images/icons/cross.png")" alt="Delete" /></a>
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>
        </div>
        <!-- End .content-box-content -->
    </div>
    <script type="text/javascript">
        function EditUser(username) {
            $("#usernameEdit").val(username);
        }
        function clickFix(obj) {
            if ((obj.id == "btnEditUser" && (
                                        $.trim($("#facebox #passwordEdit").val()) == "" ||
                                        $.trim($("#facebox #usernameEdit").val()) == ""
                                        )) ||
               (obj.id == "btnAddNewUser" && (
                                        $.trim($("#facebox #passwordNew").val()) == "" ||
                                        $.trim($("#facebox #usernameNew").val()) == ""
                                        ))
            ) 
            {
                alert("Hãy điền đầy đủ thông tin");
                return false;
            }
        }
    </script>
}
else
{
    <p>
        No user available!</p>
}
@section Lazy{
    <script type="text/javascript">
        $(".current").removeClass("current");
        $("#qlnd").addClass("current");
        

    </script>
}
